package com.example.springboot.controller;

import com.example.springboot.base.Result;
import com.example.springboot.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户行为的请求
 */

@RestController
@RequestMapping("/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/login")
    public Result login(
            @RequestParam("username") String username,
            @RequestParam("password") String password
    ) {
        return userInfoService.userLogin(username, password);
    }

    @PostMapping("/register")
    public Result register(
            @RequestParam("userName") String userName,
            @RequestParam("password") String password
    ) {
        return userInfoService.userRegister(userName, password);
    }


    @PostMapping("/token")
    public Result token(
            HttpServletRequest request
    ) {
        String token = request.getHeader("token");
        return userInfoService.token(token);

    }
}

